package cn.yl.caner.web;

import java.io.IOException;
import java.util.Map;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import cn.yl.caner.domain.AddData;
import cn.yl.caner.service.AddService;


public class AddServlet extends HttpServlet {
		//对帐号添加资料
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		//键值对方式进行封装
		Map<String, String[]> properties = request.getParameterMap();
		AddData adddata = new AddData();
		try {
			BeanUtils.populate(adddata, properties);
		} catch (Exception e) {
			e.printStackTrace();
		}
		String add_username =(String) request.getSession().getAttribute("login_username");
		System.out.println("add_username"+add_username);
		adddata.setAdd_username(add_username);
		AddService addservice = new AddService();
		int addnumber = addservice.addAccount(adddata);
		//状态码判断
		if(addnumber == 0) {
			System.out.println("提交失败");
			response.sendRedirect(request.getContextPath()+"/findfail.jsp");
		}else {
			System.out.println("提交成功");
			response.sendRedirect(request.getContextPath()+"/success.jsp");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}